package com.mes.web.controller.biz;

import java.util.List;
import java.util.HashMap;
import java.util.Map;
import com.mes.common.annotation.Log;
import com.mes.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.mes.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mes.common.enums.BusinessType;
import com.mes.common.utils.poi.ExcelUtil;
import com.mes.framework.cache.DictUtils;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.mes.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.mes.biz.domain.BizParts;
import com.mes.biz.service.BizPartsService;

/**
 * 配件单Controller
 * @author swf
 * @email swf
 * @date 2023-09-12
 */
@RestController
@RequestMapping("/biz/bizParts")
public class BizPartsController extends BaseController {

    @Autowired
    private BizPartsService bizPartsService;

    /**
     * 查询配件单列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizParts:list')")
    @GetMapping("/list")
    public R<PageInfo> list(BizParts bizParts, HttpServletRequest request, HttpServletResponse response) {
        bizParts.setPage(new PageDomain(request, response));
        return R.data(bizPartsService.findPage(bizParts));
    }

    /**
     * 获取配件单详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizParts:query')")
    @GetMapping(value = "/{id}")
    public R<BizParts> detail(@PathVariable("id") String id) {
        return R.data(bizPartsService.get(id));
    }

    /**
     * 新增配件单
     */
    @PreAuthorize("@ss.hasPermi('biz:bizParts:add')")
    @Log(title = "配件单", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  BizParts bizParts) {
        return R.status(bizPartsService.create(bizParts));
    }

    /**
     * 修改配件单
     */
    @PreAuthorize("@ss.hasPermi('biz:bizParts:edit')")
    @Log(title = "配件单", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated BizParts bizParts) {
        return R.status(bizPartsService.update(bizParts));
    }

    /**
     * 删除配件单
     */
    @PreAuthorize("@ss.hasPermi('biz:bizParts:remove')")
    @Log(title = "配件单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(bizPartsService.deleteBizPartsByIds(ids));
    }


    /**
     * 导出配件单列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizParts:export')")
    @Log(title = "配件单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(BizParts bizParts) {
        List<BizParts> list = bizPartsService.findList(bizParts);
        ExcelUtil<BizParts> util = new ExcelUtil<BizParts>(BizParts.class);
        return util.exportExcel(list, "配件单数据");
    }
	
    /**
     * 根据字典类型查询字典数据信息等其他自定义信息
     */
    @GetMapping(value = "/getInitData/{dictTypes}")
    public R getInitData(@PathVariable String dictTypes) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.putAll(DictUtils.getMultiDictList(dictTypes));
        return R.data(dataMap);
    }

}
